﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InfoSource.Utilities;
using InfoSource.Data;
using System.Net.Mail;
using System.Net;
using InfoSource.Models.objects;

namespace InfoSource.Controllers
{
    public class TestController : Controller
    {
        //
        // GET: /Test/

        public ActionResult GMapsPolygonTest(string zipcode)
        {
			zipcode = zipcode ?? "80004";

			ViewBag.zipcode = zipcode;
			ViewBag.coordinates = Helpers.GetCoordinatesFromKMLFile(zipcode);

            return View();
        }

		/*----------------------------------------------------------*/
		public ActionResult GetSeniorAndSpecialistForZipCode(int zipcode)
		{
			var techs = TechnicianRequests.GetSeniorAndSpecialistForZipcode(zipcode);

			return Json(techs, JsonRequestBehavior.AllowGet);
		}

        /*----------------------------------------------------------*/
        public ActionResult SendEmail()
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.To.Add(new MailAddress("brian.k.draper@xcelenergy.com"));
                msg.To.Add(new MailAddress("mark.j.banegas@xcelenergy.com"));
                msg.To.Add(new MailAddress("terilee.henderson@xcelenergy.com"));
                msg.To.Add(new MailAddress("jeffrey.s.herman@xcelenergy.com"));
                msg.To.Add(new MailAddress("virginia.bernard@xcelenergy.com"));
                msg.To.Add(new MailAddress("bkdraper4@gmail.com"));
                msg.To.Add(new MailAddress("bkdraper@msn.com"));
                msg.Subject = "Test automated email from appt confirmations";
                msg.From = new MailAddress("AppointmentConfirmation@XcelEnergy.com");
                msg.Body = "<style type='text/css'>table{border:1px solid blue;} td{color:red}</style><table border='1'><tr><td>test programatically generated message sent from appt confirm email</td></tr></table>";
                msg.IsBodyHtml = true;


                SmtpClient client = new SmtpClient();
                client.Host = "smtp.xcelenergy.com";
                client.Port = 25;

                NetworkCredential user = new NetworkCredential("corp\\drpb99", "Abcd123i");
                client.Credentials = CredentialCache.DefaultNetworkCredentials;
                //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Send(msg);

                return Content("success: " + DateTime.Now.ToString("hh:mm:ss"));
            }
            catch (Exception e)
            {
                return Content(e.Message + ": " + DateTime.Now.ToString("hh:mm:ss"));
            }

        }


        /*----------------------------------------------------------*/
        public JsonResult SaveTemplate(int? id, string templateName, string templateBody)
        {
            DBResult result = AppointmentRemindersRequests.SaveTemplate(id, templateName, templateBody);

            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /*----------------------------------------------------------*/
		public JsonResult TestAdvServDB()
		{
			AdvServDB db = new AdvServDB();
			Contract contract = db.Contracts.FirstOrDefault();

			return Json(new Dictionary<string,string>(){{"name", contract.First_Name}});
		}

    }
}
